<?php

/**
 * XHTML_A, xhtml_lib
 * 
 * This file contains the source code for the XHTML_A class.
 * @author Fernando Jimenez Mocobono <fjmcool@gmail.com>
 * @version 0.1
 * @package xhtml_lib
 */

include_once "XHTML_All_Attributes_Element.php";
include_once "XHTML__Inline.php";
include_once "XHTML__Pre_Content.php";
include_once "XHTML__A_Content.php";

/**
 * The XHTML_A class is a handler for the a xhtml-strict tag as a part
 * of a xhtml-strict php-handler implementation.
 */
class XHTML_A extends XHTML_All_Attributes_Element implements XHTML__Inline, XHTML__Pre_Content {
    
    // xhtml attributes
    
    /**
     * Character encoding of the target URI.
     * 
     * @var string
     */
    protected $charSet;
    
    /**
     * MIME (Multipurpose Internet Mail Extensions) type of the target URI.
     * i.e.: text/css, text/javascript, image/gif.
     *
     * @var string
     */
    protected $type;
    
    /**
     * Name of the anchor used to create a bookmark in a document.
     * In future versions of XHTML the name attribute will be replaced by the 
     * id attribute!!
     * 
     * @var string
     */
    protected $name;
    
    /**
     * Target URI of the link.
     *
     * @var string
     */
    protected $href;
    
    /**
     * Base language of the target URI.
     *
     * @var string
     */
    protected $hrefLang;
    
    /**
     * Relationship between the current document and the target URI.
     * Valid values: alternate, appendix, bookmark, chapter, contents, 
     * copyright, glossary, help, home, index, next, prev, section, start, 
     * stylesheet, subsection.
     * 
     * @var string
     */
    protected $rel;
    
    /**
     * Relationship between the target URI and the current document.
     * Valid values: alternate, appendix, bookmark, chapter, contents, 
     * copyright, glossary, help, home, index, next, prev, section, start, 
     * stylesheet, subsection.
     * 
     * @var string
     */
    protected $rev;
    
    /**
     * Type of region to be defined for mapping in the current area tag. Used 
     * with the coords attribute.
     * Valid values: rect, rectangle, circ, circle, poly, polygon.
     * 
     * @var string
     */
    protected $shape;
    
    /**
     * Coordinates appropriate to the shape attribute to define a region of an 
     * image for image maps.
     * if shape="rect" then
     * coords="left,top,right,bottom"
     * 
     * if shape="circ" then
     * coords="centerx,centery,radius"
     * 
     * if shape="poly" then
     * coords="x1,y1,x2,y2,..,xn,yn"
     *
     * @var string
     */
    protected $coords;

    // inner elements
    
    /**
     * XHTML__A_Content elements the a tag has in its content.
     *
     * @var array
     */
    protected $elements;
    
    
    // Methods
    
    /**
     * Constructs a XHTML_A object.
     */
    function __construct()
    {
        settype($this->elements, "array");
    }
    
    /**
     * Sets the character encoding of the target URI.
     * 
     * @param string $charSet
     */
    function setCharSet($charSet)
    {
        $this->charSet = $charSet;
    }
    
    /**
     * Gets the character encoding of the target URI.
     * 
     * @return string
     */
    function getCharSet()
    {
        return $this->charSet;
    }
    
    /**
     * Sets the MIME (Multipurpose Internet Mail Extensions) type of the target URI.
     * i.e.: text/css, text/javascript, image/gif.
     *
     * @param string $type
     */
    function setType($type)
    {
        $this->type = $type;
    }
    
    /**
     * Gets the MIME (Multipurpose Internet Mail Extensions) type of the target URI.
     * i.e.: text/css, text/javascript, image/gif.
     * 
     * @return string
     */
    function getType()
    {
        return $this->type;
    }
    
    /**
     * Sets the name of the anchor used to create a bookmark in a document.
     * In future versions of XHTML the name attribute will be replaced by the 
     * id attribute!!
     * 
     * @param string $name
     */
    function setName($name)
    {
        $this->name = $name;
    }
    
    /**
     * Gets the name of the anchor used to create a bookmark in a document.
     * In future versions of XHTML the name attribute will be replaced by the 
     * id attribute!!
     *
     * @return unknown
     */
    function getName()
    {
        return $this->name;
    }
    
    /**
     * Sets the target URI of the link.
     *
     * @param string $href
     */
    function setHref($href)
    {
        $this->href = $href;
    }
    
    /**
     * Gets the target URI of the link.
     *
     * @return string
     */
    function getHref()
    {
        return $this->href;
    }
    
    /**
     * Sets the base language of the target URI.
     *
     * @param string $hrefLang
     */
    function setHrefLang($hrefLang)
    {
        $this->hrefLang = $hrefLang;
    }
    
    /**
     * Gets the base language of the target URI.
     *
     * @return string
     */
    function getHrefLang()
    {
        return $this->hrefLang;
    }
    
    /**
     * Sets the relationship between the current document and the target URI.
     * Valid values: alternate, appendix, bookmark, chapter, contents, 
     * copyright, glossary, help, home, index, next, prev, section, start, 
     * stylesheet, subsection.
     * 
     * @param string $rel
     */
    function setRel($rel)
    {
        $this->rel = $rel;
    }
    
    /**
     * Gets the relationship between the current document and the target URI.
     * Valid values: alternate, appendix, bookmark, chapter, contents, 
     * copyright, glossary, help, home, index, next, prev, section, start, 
     * stylesheet, subsection.
     *
     * @return string
     */
    function getRel()
    {
        return $this->rel;
    }
    
    /**
     * Sets the relationship between the target URI and the current document.
     * Valid values: alternate, appendix, bookmark, chapter, contents, 
     * copyright, glossary, help, home, index, next, prev, section, start, 
     * stylesheet, subsection.
     *
     * @param string $rev
     */
    function setRev($rev)
    {
        $this->rev = $rev;
    }
    
    /**
     * Gets the relationship between the target URI and the current document.
     * Valid values: alternate, appendix, bookmark, chapter, contents, 
     * copyright, glossary, help, home, index, next, prev, section, start, 
     * stylesheet, subsection.
     * 
     * @return string
     */
    function getRev()
    {
        return $this->rev;
    }
    
    /**
     * Sets the type of region to be defined for mapping in the current area 
     * tag. Used with the coords attribute.
     * Valid values: rect, rectangle, circ, circle, poly, polygon.
     * 
     * @param string $shape
     */
    function setShape($shape)
    {
        $this->shape = $shape;
    }
    
    /**
     * Gets the type of region to be defined for mapping in the current area 
     * tag. Used with the coords attribute.
     * Valid values: rect, rectangle, circ, circle, poly, polygon.
     * 
     * @return string
     */
    function getShape()
    {
        return $this->shape;
    }
    
    /**
     * Sets the coordinates appropriate to the shape attribute to define a 
     * region of an image for image maps.
     * if shape="rect" then
     * coords="left,top,right,bottom"
     * 
     * if shape="circ" then
     * coords="centerx,centery,radius"
     * 
     * if shape="poly" then
     * coords="x1,y1,x2,y2,..,xn,yn"
     * 
     * @package string $coords
     */
    function setCoords($coords)
    {
        $this->coords = $coords;
    }
    
    /**
     * Gets the coordinates appropriate to the shape attribute to define a 
     * region of an image for image maps.
     * if shape="rect" then
     * coords="left,top,right,bottom"
     * 
     * if shape="circ" then
     * coords="centerx,centery,radius"
     * 
     * if shape="poly" then
     * coords="x1,y1,x2,y2,..,xn,yn"
     * 
     * @return string
     */
    function getCoords()
    {
        return $this->coords;
    }
    
    /**
     * Sets the XHTML__A_Content elements array.
     *
     * @param array
     */
    function setElements($elements) {
        $this->elements = $elements;
    }
    
    /**
     * Gets the XHTML__A_Content elements array.
     *
     * @return array
     */
    function getElements()
    {
        return $this->elements;
    }
    
    /**
     * Adds a XHTML__A_Content element to the inner array of this object.
     * 
     * @param XHTML__A_Content
     */
    function addElement(XHTML__A_Content $element)
    {
        array_push($this->elements, $element);
    }
    
    /**
     * Removes a XHTML__A_Content element from the inner array of this object.
     * 
     * @param XHTML__A_Content
     */
    function removeElement(XHTML__A_Content $element)
    {
        if (($res = array_search($element, $this->elements)) !== false) {
            unset($this->element[$res]);
        }
    }

    // Overriding the toString method for a proper implementation.
    
    /**
    * Returns the string representation for echoing the class atributes.
    *
    * @return string
    */
    function toString()
    {
        $auxString = "<a".parent::toString();
        
        /*
         * Additions of the body own attributes to the return string.
         */
        if (isset($this->charSet)) {
            $auxString = $auxString."charset=\"".$this->charSet."\" ";
        }
        
        if (isset($this->type)) {
            $auxString = $auxString."type=\"".$this->type."\" ";
        }
        
        if (isset($this->name)) {
            $auxString = $auxString."name=\"".$this->name."\" ";
        }
        
        if (isset($this->href)) {
            $auxString = $auxString."name=\"".$this->href."\" ";
        }
        
        if (isset($this->hrefLang)) {
            $auxString = $auxString."hreflang=\"".$this->hrefLang."\" ";
        }
        
        if (isset($this->rel)) {
            $auxString = $auxString."rel=\"".$this->rel."\" ";
        }
        
        if (isset($this->rev)) {
            $auxString = $auxString."rev=\"".$this->rev."\" ";
        }
        
        if (isset($this->shape)) {
            $auxString = $auxString."shape=\"".$this->shape."\" ";
        }
        
        if (isset($this->coords)) {
            $auxString = $auxString."coords=\"".$this->coords."\" ";
        }
        
        $auxString = $auxString.">\n";
        
        /*
         * Additions of the inner elements of the a element to the return 
         * string.
         */
        if (count($this->elements) > 0) {
            foreach ($this->elements as $element) {
                $auxString = $auxString.$element->toString();
            }
        }
        
        $auxString = $auxString."</a>\n";
        
        return $auxString;
    }
    
}

?>